﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.UI.HtmlControls;

namespace NJL.Web.Visitor
{
    public partial class Default : BasePageVisitor
    {
        NJL.BLL.NJL_NEWS bllNews = new BLL.NJL_NEWS();
        NJL.BLL.NJL_USER bllUser = new BLL.NJL_USER();
        NJL.BLL.NJL_PERSON bllPerson = new BLL.NJL_PERSON();
        NJL.BLL.NJL_COMPANY bllCompany = new BLL.NJL_COMPANY();
        NJL.BLL.NJL_LEAVE_MESSAGE bllMessage = new BLL.NJL_LEAVE_MESSAGE();

        NJL.Model.NJL_LEAVE_MESSAGE modelMessage = new Model.NJL_LEAVE_MESSAGE();
        NJL.Model.NJL_USER modelUserHost;
        NJL.Model.NJL_PERSON modelPerson;
     

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bind();
                LoadPageSEO();
            }
        }
        /// <summary>
        /// 加载页面SEO
        /// </summary>
        private void LoadPageSEO()
        {
            Page.Title = modelUserHost.USER_NAME + "的乡间小屋";

            //HtmlMeta myMeta = new HtmlMeta();
            //myMeta.Name = "Keywords";
            //myMeta.Content = bllPerson.SEO_KEYWORDS;
            //this.Header.Controls.Add(myMeta);

            //HtmlMeta myMeta1 = new HtmlMeta();
            //myMeta1.Name = "Description";
            //myMeta1.Content = bllPerson.SEO_DESCRIPTION;
            //this.Header.Controls.Add(myMeta1);
        }

        void bind()
        {
         

            if (Request.QueryString["uid"] == null || Request.QueryString["uid"] == "")
            {
                Response.Redirect("/", true);
            }

            modelUserHost = bllUser.GetModel(Request.QueryString["uid"]);
            if (modelUserHost == null)
            {
                Response.Redirect("/", true);
            }

    

            #region 游记
            DataSet dsTravel = bllNews.GetList(8,"NJL_PERSON_ID='" + Request.QueryString["uid"] + "'","ID desc");
            rptTravel.DataSource = dsTravel;
            rptTravel.DataBind();
            //string[] param = { "uid" };
            //page.InnerHtml = Royalsoft.Common.Pager.GetPageNum(dsTravel, rptTravel, 10, param, "/wanjia/");
            #endregion

        
            #region 点击次数
            modelPerson = bllPerson.GetModelByUserId(Request.QueryString["uid"]);
            bllPerson.updateHitandDate(modelPerson.ID);
            #endregion
        }

        //protected void btnComment_Click(object sender, EventArgs e)
        //{


        //    modelMessage.ID = DateTime.Now.ToString("yyyyMMddHHmmssfff") + new Random().Next(100, 999).ToString();
        //    modelMessage.LEAVE_MESSAGE_TYPE_CODE = 1;
        //    modelMessage.LEAVE_MESSAGE = txtComment.Text.Trim();
        //    modelMessage.NJL_USER_ID = Request.QueryString["uid"].ToString();
        //    modelMessage.CREATE_USER_ID = new BasePage().UserId;
        //    modelMessage.CREATE_USER_NAME = new BasePage().UserName;
        //    modelMessage.CREATE_DATE_TIME = DateTime.Now;
        //    bllMessage.Add(modelMessage);
        //    Royalsoft.Common.MessageBox.ShowAndRedirect(this, "留言成功", Request.RawUrl);
        //    modelPerson = bllPerson.GetModelByUserId(Request.QueryString["uid"]);
        //    if (bllPerson.updateCommentHitAndDate(modelPerson.ID))
        //    {

        //    }



        //}
        //protected void rptCommentList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        //{
        //    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        //    {
        //        DataRowView grv = (DataRowView)e.Item.DataItem;
        //        string userId = grv["CREATE_USER_ID"].ToString();
        //        Image imgUserHead = e.Item.FindControl("imgUserHead") as Image;
        //        modelPerson = bllPerson.GetModelByUserId(userId);
        //        if (modelPerson != null)
        //        {
        //            if (modelPerson.IMAGE_CODE != "")
        //            {
        //                imgUserHead.ImageUrl = GetImageUrl(modelPerson.IMAGE_CODE, "U2");
        //                imgUserHead.BorderWidth = 1;
        //            }
        //            else
        //            {
        //                imgUserHead.ImageUrl = "/Images/avatar.jpg";
        //                imgUserHead.BorderWidth = 1;
        //            }
        //        }
        //        LinkButton lbtn = e.Item.FindControl("lbtnDel") as LinkButton;
        //        if (UserId != "" && UserId.Equals(Request.QueryString["uid"]))
        //        {
        //            lbtn.Visible = true;
        //        }
        //        else
        //        {
        //            lbtn.Visible = false;
        //        }
        //    }
        //}

        //protected void rptCommentList_ItemCommand(object source, RepeaterCommandEventArgs e)
        //{
        //    if (e.CommandName == "Del")
        //    {
        //        string id = e.CommandArgument.ToString();
        //        if (bllMessage.Delete(id))
        //        {
        //            bind();
        //        }
        //        else
        //        {
        //            Royalsoft.Common.MessageBox.Show(this, "删除失败");
        //        }
        //    }
        //}
    }
}